﻿module VisualPhysics.Scene.Core.Tests.Utils

open VisualPhysics.Scene.Core
open VisualPhysics.Scene.Core.Operators

let equalFloats (a : float<_>) (b : float<_>) =
    if abs (float (a - b)) < 0.000001 then
        a
    else
        b

let equalMVectors (a : MVector<_>) (b : MVector<_>) =
    let ax, ay = car a
    let bx, by = car b
    if abs (float (bx - ax) + float (by - ay)) < 0.000001 then
        a
    else
        b

let equalTuples (a : (float<_> * float<_>)) (b : (float<_> * float<_>)) =
    let ax, ay = a
    let bx, by = b
    if abs (float (bx - ax + by - ay)) < 0.000001 then
        a
    else
        b

let equalListTuples a b =
    let r =
        List.zip a b
        |> List.forall (fun (a, b) -> (equalTuples a b) = a)
    if r then
        a
    else b